<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script src="/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .layui-upload-img{
            max-width: 200px;
            margin-left: 110px;
        }
        .mask{
          display: none;
          position: fixed;
          left: 0;
          top:0;
          width: 100vw;
          height: 100vh;
          background: rgba(0,0,0,0.4);
          z-index: 100;
        }
        .sku-table{
          min-width: 600px;
          min-height: 100px;
        }
        .sku-table thead,tbody,tfoot,tr,th,td{
          padding:0px;
          margin: 0px;
        }
        .sku-table thead tr{
          border-bottom: 1px solid #000;
        }
        .sku-table thead th{
          width: 200px;
          height:30px;
          line-height: 30px;
        }
        .sku-table tbody tr{
          border-bottom: 1px solid #000;
        }
        .sku-table tbody tr td{
          width: 200px;
          text-decoration: 2em;
          font-size: 16px;
          color: #666;
          text-align: center;
        }
        .sku-table tbody tr td a{
          display: block;
          min-height: 40px;
          line-height: 40px;
          width: 100%; /* 宽度设置为100%，以填满父元素 */  
          height: 100%; /* 高度设置为100%，以填满父元素 */ 
        }
        .sku-table tfoot{
          text-align: right;
        }
        .zhushi{
            color: #0a972d;
        }
        .sku-key{
          display: none;
          background-color: aliceblue;
          z-index: 101;
          width:400px;
          min-height:150px;
          display: block;
          position: fixed;
          left: 50%;
          top:50%;
          margin-top:-75px;
          margin-left:-200px;
        }
        .sku-key .key-message{
          margin: 20px 0px;
          width: 100%;
        }
        .sku-key .key-message .key-info{
            width: 100%;
            min-height: 50px;
        }
        .sku-key .key-message .key-info span{
            display: block;
            width: 100%;
            text-align: center;
            color: red;
        }
        .sku-key .key-message .key-info input{
            display: block;
            width: 75%;
            height: 40px;
            margin: 5px auto;
            border-radius: 5px;
            text-align: center;
        }
        .sku-key .key-message .key-button{
            height: 50px;
            width: 100%;
            display: block;
            text-align: center;
        } 
        .sku-key .key-message .key-button a{
            margin:10px 10px;
        }
        #fanyi{
            color: red;
        }
    </style>
  </head>
  
  <body>
    <div class="x-body">
        <div class="mask" id="mask"></div>
        <div class="sku-key" id="sku-key" style="display: none;">
            <div class="key-message">
                <input type="text" id="variable-index" style="display: none;">
                <div class="key-info" id="name">
                    <input type="text" id="keyname" required lay-verify="required" placeholder="名称">
                </div>
                <div class="key-info" id="symbol">
                    <input type="text" id="keysymbol" required lay-verify="required" placeholder="变量名">
                </div>
                <div class="key-button">
                    <a class="layui-btn" href="javascript:setskukey();">确定</a>
                    <a class="layui-btn" href="javascript:ressku();">取消</a>
                </div>
            </div>
        </div>
        <div class="sku-key" id="other-algorithm" style="display: none;">
            <div class="key-message">
                <input type="text" id="other-algorithm-index" style="display: none;">
                <div class="key-info" id="other-algorithm-name">
                    <input type="text" id="other-algorithm-list-name" required lay-verify="required" placeholder="名称">
                </div>
                <div class="key-info" id="other-algorithm-vara">
                    <input type="text" id="other-algorithm-list-vara" required lay-verify="required" placeholder="变量">
                </div>
                <div class="key-info" id="other-algorithm-algorithm">
                    <input type="text" id="other-algorithm-list-algorithm" required lay-verify="required" placeholder="公式">
                    <span id="other-algorithm-text"></span>
                </div>
                <div class="key-button">
                    <a class="layui-btn" href="javascript:setotheralgorithm();">确定</a>
                    <a class="layui-btn" href="javascript:ressku();">取消</a>
                </div>
            </div>
        </div>
        <div class="sku-key" id="other-variable" style="display: none;">
            <div class="key-message">
                <input type="text" id="other-variable-index" style="display: none;">
                <div class="key-info" id="other-variable-name">
                    <input type="text" id="other-variable-list-name" required lay-verify="required" placeholder="名称">
                </div>
                <div class="key-info" id="other-variable-vara">
                    <input type="text" id="other-variable-list-vara" required lay-verify="required" placeholder="变量">
                </div>
                <div class="key-button">
                    <a class="layui-btn" href="javascript:setothervariable();">确定</a>
                    <a class="layui-btn" href="javascript:ressku();">取消</a>
                </div>
            </div>
        </div>
        <!-- <form class="layui-form"> -->
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>标准名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="standard" name="standard" required lay-verify="required"
                    autocomplete="off" class="layui-input" value="{$info.standard|default=''}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>分类
                </label>
                <div class="layui-input-inline">
                    <select name="type_name" id="type_name">
                        {volist name="classify_list" id="value"}
                        <option value="{$value.name}" {eq name="$info.type_name" value="$value.name"}selected{/eq}>{$value.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="algorithm" class="layui-form-label layui-form-text">
                    <span class="x-red">*</span>成品体积公式
                </label>
                <div class="layui-input-block">
                    <input type="text" id="volume" name="volume" required lay-verify="required"
                           autocomplete="off" class="layui-input" value="{$info.volume|default=''}" onchange="fanyigongshi()">
                    <span id="volume_fanyi"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="algorithm" class="layui-form-label layui-form-text">
                    <span class="x-red">*</span>成品重量公式
                </label>
                <div class="layui-input-block">
                    <input type="text" id="algorithm" name="algorithm" required lay-verify="required"
                    autocomplete="off" class="layui-input" value="{$info.algorithm|default=''}" onchange="fanyigongshi()">
                    <span id="fanyi"></span>
                    <span class="zhushi">注释PI=3.1415926</span>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="blank_algorithm" class="layui-form-label layui-form-text">
                    <span class="x-red">*</span>毛胚重量公式
                </label>
                <div class="layui-input-block">
                    <input type="text" id="blank_algorithm" name="blank_algorithm" required lay-verify="required"
                    autocomplete="off" class="layui-input" value="{$info.blank_algorithm|default=''}" onchange="fanyigongshi()">
                    <span id="fanyim"></span>
                    <span class="zhushi">注释PI=3.1415926</span>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">
                    重量变量
                </label>
                <div class="layui-input-block">
                <table class="sku-table">
                    <thead>
                      <tr>
                        <th>名称</th>
                        <th>变量名</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                    <tbody id="variable_table">
                        <tr>
                            <td colspan="3">
                                <span class="zhushi">注释保留变量 MD=材质密度</span>
                            </td>
                        </tr>
                        {volist name="info.variable" id="value" key="key"}
                        {eq name="value.symbol" value="MD"}
                        <tr>
                            <td id="name_{$key}"><a href="javascript:;">{$value.name}</a></td>
                            <td id="symbol_{$key}"><a href="javascript:;">{$value.symbol}</a></td>
                            <td></td>
                        </tr>
                        {else}
                        <tr>
                            <td id="name_{$key}"><a href="javascript:;" onclick="variable_save('name_{$key}','name','{$value.name}')">{$value.name}</a></td>
                            <td id="symbol_{$key}"><a href="javascript:;" onclick="variable_save('symbol_{$key}','symbol','{$value.symbol}')">{$value.symbol}</a></td>
                            <td><a href="javascript:variable_del({$key});">删除</a></td>
                        </tr>
                        {/eq}
                        {/volist}
                    </tbody>
                    <tfoot>
                      <tr>
                        <td colspan="3"><a href="javascript:;" onclick="variable_add()" class="layui-btn">新增</a></td>
                      </tr>
                    </tfoot>
                  </table>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">
                    其他算法
                </label>
                <div class="layui-input-block">
                <table class="sku-table">
                    <thead>
                      <tr>
                        <th>名称</th>
                        <th>变量名</th>
                        <th>算法</th>
                        <th>所属</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                    <tbody id="other_algorithm_table">
                        <tr>
                            <td colspan="5">
                                <span class="zhushi">注释保留变量 weight=根据上面公式得出的重量 MP1=材料费用 MP2=材料加工费 RP=回炉费</span>
                            </td>
                        </tr>
                        {volist name="info.other_algorithm" id="value" key="key"}
                        <tr>
                            <td id="other_algorithm_name_{$key}"><a href="javascript:;" onclick="other_algorithm_save('{$key}','name','{$value.name}')">{$value.name}</a></td>
                            <td id="other_algorithm_vara_{$key}"><a href="javascript:;" onclick="other_algorithm_save('{$key}','vara','{$value.vara}')">{$value.vara}</a></td>
                            <td id="other_algorithm_algorithm_{$key}" style="min-width: 500px;"><a href="javascript:;" onclick="other_algorithm_save('{$key}','algorithm','{$value.algorithm}')">{$value.algorithm}</a></td>
                            <td>
                                <select id="other_algorithm_id_{$key}" onchange="set_other_algorithm({$key},this.value,'id')">
                                    <option value="1" {eq name="$value.id" value="1"}selected{/eq}>锻打毛胚</option>
                                    <option value="2" {eq name="$value.id" value="2"}selected{/eq}>卷板毛胚</option>
                                    <option value="3" {eq name="$value.id" value="3"}selected{/eq}>割坂毛胚</option>
                                </select>
                            </td>
                            <td><a href="javascript:other_algorithm_del({$key});">删除</a></td>
                        </tr>
                        {/volist}
                    </tbody>
                    <tfoot>
                      <tr>
                        <td colspan="5"><a href="javascript:;" onclick="other_algorithm_add()" class="layui-btn">新增</a></td>
                      </tr>
                    </tfoot>
                  </table>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">
                    其他变量
                </label>
                <div class="layui-input-block">
                <table class="sku-table">
                    <thead>
                      <tr>
                        <th>名称</th>
                        <th>变量名</th>
                        <th>类型</th>
                        <th>所属</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                    <tbody id="other_variable_table">
                        <tr>
                            <td colspan="5">
                                <span class="zhushi">注释保留变量 MPO=材料费用 MPT=材料加工费 RP=回炉费</span>
                            </td>
                        </tr>
                        {volist name="info.other_variable" id="value" key="key"}
                        <tr>
                            <td id="other_variable_name_{$key}"><a href="javascript:;" onclick="other_variable_save({$key},'name','{$value.name}')">{$value.name}</a></td>
                            <td id="other_variable_vara_{$key}"><a href="javascript:;" onclick="other_variable_save({$key},'symbol','{$value.vara}')">{$value.vara}</a></td>
                            <td>
                                <select id="other_variable_type_{$key}" onchange="set_other_variable({$key},this.value,'type')">
                                    <option value="1" {eq name="$value.type" value="1"}selected{/eq}>输入参数</option>
                                    <option value="2" {eq name="$value.type" value="2"}selected{/eq}>材料选择</option>
                                    <option value="3" {eq name="$value.type" value="3"}selected{/eq}>加工费选择</option>
                                </select>
                            </td>
                            <td>
                                <select id="other_variable_id_{$key}" onchange="set_other_variable({$key},this.value,'id')">
                                    <option value="1" {eq name="$value.id" value="1"}selected{/eq}>锻打毛胚</option>
                                    <option value="2" {eq name="$value.id" value="2"}selected{/eq}>卷板毛胚</option>
                                    <option value="3" {eq name="$value.id" value="3"}selected{/eq}>割坂毛胚</option>
                                </select>
                            </td>
                            <td><a href="javascript:other_variable_del({$key});">删除</a></td>
                        </tr>
                        {/volist}
                    </tbody>
                    <tfoot>
                      <tr>
                        <td colspan="5"><a href="javascript:;" onclick="other_variable_add()" class="layui-btn">新增</a></td>
                      </tr>
                    </tfoot>
                  </table>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">
                    简单描述
                </label>
                <div class="layui-input-block">
                    <input placeholder="请输入内容" type="text" id="info" name="info" class="layui-input" value="{$info.info|default=''}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    确认
                </button>
            </div>
        <!-- </form> -->
    </div>
    <script>
        var variable = '<?php echo $variable ?>',
            other_algorithm = '<?php echo $other_algorithm ?>',
            other_variable = '<?php echo $other_variable ?>';
        variable = JSON.parse(variable);
        other_algorithm = JSON.parse(other_algorithm);
        other_variable = JSON.parse(other_variable);
        console.log(variable);
        // 创建一个替换映射对象  
        var replacements = variable.reduce((map, item) => {  
            map[item.symbol] = item.name;  
            return map;  
        }, {});  
        function replaceSymbols(str, replacements) {  
            return str.replace(/(\b\w+\b)/g, function(match) {  
                return replacements[match] || match; // 如果替换映射中没有找到，则保留原样  
            });  
        }  
        function fanyigongshi(){
            let str = document.getElementById('algorithm').value,
                string = document.getElementById('blank_algorithm').value,
                text = document.getElementById('volume').value;
            document.getElementById('fanyi').innerText = replaceSymbols(str,replacements);
            document.getElementById('fanyim').innerText = replaceSymbols(string,replacements);
            document.getElementById('volume_fanyi').innerText = replaceSymbols(text.replacements);
        }
        fanyigongshi();
        function variable_add(){
            blockkey();
            document.getElementById('variable-index').value='';
            document.getElementById('keyname').value = '';
            document.getElementById('keysymbol').value = '';
            document.getElementById('name').style = 'display:block';
            document.getElementById('symbol').style = 'display:block';
        }

        function variable_save(index,vara,data){
            blockkey();
            document.getElementById(vara).style = 'display:block';
            document.getElementById('variable-index').value=index;
            if(vara == 'symbol'){
                document.getElementById('name').style = 'display:none';
                document.getElementById('keyname').value = '';
                document.getElementById('keysymbol').value = data;
            }else{
                document.getElementById('symbol').style = 'display:none';
                document.getElementById('keysymbol').value = '';
                document.getElementById('keyname').value = data;
            }
        }

        function setskukey(){
            let index = document.getElementById('variable-index').value;
            let a = document.getElementById('keysymbol').value;
            let b = document.getElementById('keyname').value;
            if (index != ''){
                if (a){
                    document.getElementById(index).innerHTML = '<a href="javascript:;" onclick="variable_save(\'' + index + '\',\'symbol\',\'' + a + '\')">' + a +'</a>';
                    let number = index.replace('symbol_','');
                    console.log(number);
                    variable[number - 1].symbol = a;
                }else{
                    document.getElementById(index).innerHTML = '<a href="javascript:;" onclick="variable_save(\'' + index + '\',\'name\',\'' + b + '\')">' + b + '</a>';
                    let number = index.replace('name_','');
                    variable[number - 1].name = b;
                }
            }else{
                let number = document.getElementById('variable_table').getElementsByTagName('tr').length;
                let string = '<tr>';
                string +='<td id="name_' + number + '"><a href="javascript:;" onclick="variable_save(\'name_' + number + '\',\'name\',\'' + b + '\')">' + b + '</a></td>';
                string += '<td id="symbol_' + number + '"><a href="javascript:;" onclick="variable_save(\'symbol_' + number + '\',\'symbol\',\'' + a + '\')">' + a + '</a></td>';
                string += '<td><a href="javascript:variable_del(' + number + ');">删除</a></td>'
                string += '</tr>';
                document.getElementById('variable_table').innerHTML += string;
                variable.push({name:b,symbol:a});
            }
            console.log(variable);
            fanyigongshi();
            ressku();
        }

        function variable_del(index){
            let tr = document.getElementById('variable_table').getElementsByTagName('tr')[index];
            // document.getElementById('variable_table').removeChild(tr);
            tr.style = 'display:none';
            variable.splice(index - 1,1);
            console.log(variable);
        }

        function other_algorithm_add(){
            document.getElementById('mask').style = 'display:block';
            document.getElementById('other-algorithm').style = 'display:block';
            document.getElementById('other-algorithm-list-name').value = '';
            document.getElementById('other-algorithm-list-algorithm').value = '';
            document.getElementById('other-algorithm-list-vara').value = '';
            document.getElementById('other-algorithm-name').style = 'display:block';
            document.getElementById('other-algorithm-algorithm').style = 'display:block';
            document.getElementById('other-algorithm-vara').style = 'display:block';

        }

        function other_algorithm_save(index,type,value){
            document.getElementById('mask').style = 'display:block';
            document.getElementById('other-algorithm-index').value = index;
            document.getElementById('other-algorithm').style = 'display:block';
            document.getElementById('other-algorithm-name').style = 'display:none';
            document.getElementById('other-algorithm-algorithm').style = 'display:none';
            document.getElementById('other-algorithm-vara').style = 'display:none';
            document.getElementById('other-algorithm-list-name').value = '';
            document.getElementById('other-algorithm-list-algorithm').value = '';
            document.getElementById('other-algorithm-list-vara').value = '';
            if (type == 'name'){
                document.getElementById('other-algorithm-name').style = 'display:block';
                document.getElementById('other-algorithm-list-name').value = value;
            }else if(type == 'algorithm'){
                document.getElementById('other-algorithm-algorithm').style = 'display:block';
                document.getElementById('other-algorithm-list-algorithm').value = value;
                otherfanyigongshi(value);
            }else{
                document.getElementById('other-algorithm-vara').style = 'display:block';
                document.getElementById('other-algorithm-list-vara').value = value;
            }
        }

        function setotheralgorithm(){
            let index = document.getElementById('other-algorithm-index').value;
            let a = document.getElementById('other-algorithm-list-name').value;
            let b = document.getElementById('other-algorithm-list-vara').value;
            let c = document.getElementById('other-algorithm-list-algorithm').value;
            if (index != ''){
                if (a){
                    document.getElementById('other_algorithm_name_' + index).innerHTML = '<a href="javascript:;" onclick="other_algorithm_save(\'' + index + '\',\'name\',\'' + a + '\')">' + a +'</a>';
                    other_algorithm[index - 1].name = a;
                }else if(b){
                    document.getElementById('other_algorithm_vara_' + index).innerHTML = '<a href="javascript:;" onclick="other_algorithm_save(\'' + index + '\',\'vara\',\'' + b + '\')">' + b + '</a>';
                    other_algorithm[index - 1].vara = b;
                }else{
                    document.getElementById('other_algorithm_algorithm_' + index).innerHTML = '<a href="javascript:;" onclick="other_algorithm_save(\'' + index + '\',\'algorithm\',\'' + c + '\')">' + c + '</a>';
                    other_algorithm[index - 1].algorithm = c;
                }
            }else{
                let number = document.getElementById('other_algorithm_table').getElementsByTagName('tr').length;
                let string = '<tr>';
                string +='<td id="other_algorithm_name_' + number + '"><a href="javascript:;" onclick="other_algorithm_save(' + number + ',\'name\',\'' + b + '\')">' + a + '</a></td>';
                string += '<td id="other_algorithm_vara_' + number + '"><a href="javascript:;" onclick="other_algorithm_save(' + number + ',\'vara\',\'' + a + '\')">' + b + '</a></td>';
                string += '<td id="other_algorithm_algorithm_' + number + '"><a href="javascript:;" onclick="other_algorithm_save(' + number + ',\'algorithm\',\'' + c + '\')">' + c + '</a></td>';
                string += '<td><select id="other_algorithm_id_{$key}"><option value="1">锻打毛胚</option><option value="2">卷板毛胚</option><option value="3">割坂毛胚</option></select></td>';
                string += '<td><a href="javascript:other_algorithm_del(' + number + ');">删除</a></td>';
                string += '</tr>';
                document.getElementById('other_algorithm_table').innerHTML += string;
                other_algorithm.push({name:a,vara:b,algorithm:c});
            }
            console.log(other_algorithm);
            //fanyigongshi();
            ressku();
        }

        function other_algorithm_del(index){
            let tr = document.getElementById('other_algorithm_table').getElementsByTagName('tr')[index];
            // document.getElementById('other_algorithm_table').removeChild(tr);
            tr.style = 'display:none';
            other_algorithm.splice(index - 1,1);
            console.log(other_algorithm);
        }

        // function otherReplaceSymbols(str, replacements) {  
        //     // 注意这里我们使用了 replacements 参数，而不是 replacements 变量  
        //     return str.replace(/(\b\w+\b)/g, function(match) {  
        //         return replacements[match] || match; // 如果替换映射中没有找到，则保留原样  
        //     });  
        // }

        function otherfanyigongshi(string){
            let otherReplacements = other_variable.reduce((map, item) => {  
                map[item.vara] = item.name;  
                return map;  
            }, {});
            let otherReplaceSymbols = function(str, replacements){
                // 注意这里我们使用了 replacements 参数，而不是 replacements 变量  
                return str.replace(/(\b\w+\b)/g, function(match) {  
                    return replacements[match] || match; // 如果替换映射中没有找到，则保留原样  
                });  
            }
            let replaceMultiple = function(str, find, replace) {  
                // 确保 find 和 replace 都是数组，并且长度相同  
                if (!Array.isArray(find) || !Array.isArray(replace) || find.length !== replace.length) {  
                    throw new Error('find and replace must be arrays of the same length');  
                }  
            
                // 使用 reduce 从左到右替换所有匹配的子串  
                return find.reduce((result, curr, index) => {  
                    // 使用正则表达式和全局标志 'g' 来替换所有匹配的子串  
                    // 注意：这里假设 find 数组中的项不包含正则表达式特殊字符  
                    // 如果需要处理这些字符，你可能需要先对它们进行转义  
                    const regex = new RegExp(curr, 'g');  
                    return result.replace(regex, replace[index]);  
                }, str);  
            }
            string = otherReplaceSymbols(string,otherReplacements);
            document.getElementById('other-algorithm-text').innerText = replaceMultiple(string,['weight','MPO','MPT','RP'],['重量','材料费用','加工费','回炉费']);
        
        }            

        function set_other_algorithm(index,value,vara){
            other_algorithm[index - 1][vara] = value;
            console.log(other_variable);
        }

        function other_variable_add(){
            document.getElementById('mask').style = 'display:block';
            document.getElementById('other-variable').style = 'display:block';
            document.getElementById('other-variable-list-name').value = '';
            document.getElementById('other-variable-list-vara').value = '';
            document.getElementById('other-variable-name').style = 'display:block';
            document.getElementById('other-variable-vara').style = 'display:block';

        }

        function other_variable_save(index,type,value){
            document.getElementById('mask').style = 'display:block';
            document.getElementById('other-variable-index').value = index;
            document.getElementById('other-variable').style = 'display:block';
            document.getElementById('other-variable-name').style = 'display:none';
            document.getElementById('other-variable-vara').style = 'display:none';
            document.getElementById('other-variable-list-name').value = '';
            document.getElementById('other-variable-list-vara').value = '';
            if (type == 'name'){
                document.getElementById('other-variable-name').style = 'display:block';
                document.getElementById('other-variable-list-name').value = value;
            }else{
                document.getElementById('other-variable-vara').style = 'display:block';
                document.getElementById('other-variable-list-vara').value = value;
            }
        }

        function setothervariable(){
            let index = document.getElementById('other-variable-index').value;
            let a = document.getElementById('other-variable-list-name').value;
            let b = document.getElementById('other-variable-list-vara').value;
            console.log(index);
            if (index != ''){
                if (a){
                    document.getElementById('other_variable_name_' + index).innerHTML = '<a href="javascript:;" onclick="other_variable_save(' + index + ',\'name\',\'' + a + '\')">' + a +'</a>';
                    other_variable[index - 1].name = a;
                }else{
                    document.getElementById('other_variable_vara_' + index).innerHTML = '<a href="javascript:;" onclick="other_variable_save(' + index + ',\'vara\',\'' + b + '\')">' + b + '</a>';
                    other_variable[index - 1].vara = b;
                }
            }else{
                let number = document.getElementById('other_algorithm_table').getElementsByTagName('tr').length;
                let string = '<tr>';
                string +='<td id="other_variable_name_' + number + '"><a href="javascript:;" onclick="other_variable_save(' + number + ',\'name\',\'' + b + '\')">' + a + '</a></td>';
                string += '<td id="other_variable_vara_' + number + '"><a href="javascript:;" onclick="other_variable_save(' + number + ',\'vara\',\'' + a + '\')">' + b + '</a></td>';
                string += '<td><select id="other_variable_type_' + number + '" onchange="set_other_variable(' + number + ',this.value,\'type\')"><option value="1">输入参数</option><option value="2">材料选择</option><option value="3">加工费选择</option></select></td>';
                string += '<td><select id="other_variable_id_{$key}"><option value="1">锻打毛胚</option><option value="2">卷板毛胚</option><option value="3">割坂毛胚</option></select></td>';
                string += '<td><a href="javascript:other_variable_del(' + number + ');">删除</a></td>';
                string += '</tr>';
                document.getElementById('other_variable_table').innerHTML += string;
                other_variable.push({name:a,vara:b,algorithm:c});
            }
            console.log(other_variable);
            //fanyigongshi();
            ressku();
        }

        function other_variable_del(index){
            let tr = document.getElementById('other_variable_table').getElementsByTagName('tr')[index];
            // document.getElementById('other_variable_table').removeChild(tr);
            tr.style = 'display:none';
            other_variable.splice(index - 1,1);
            console.log(other_variable);
        }

        function set_other_variable(index,value,vara){
            other_variable[index - 1][vara] = value;
            console.log(other_variable);
        }

        function blockkey(){
            document.getElementById('mask').style = 'display:block';
            document.getElementById('sku-key').style = 'display:block';
        }
        function ressku(){
            document.getElementById('name').style = 'display:none';
            document.getElementById('symbol').style = 'display:none';
            document.getElementById('mask').style = 'display:none';
            document.getElementById('sku-key').style = 'display:none';
            document.getElementById('other-algorithm').style = 'display:none';
            document.getElementById('other-variable').style = 'display:none';
        }

        
    </script>
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            name: function(value){
              if(value.length < 2){
                return '昵称至少得2个字符啊';
              }
            }
          });

          //监听提交
          form.on('submit(add)', function(data){
            let standard = {
                info:document.getElementById('info').value,
                standard:document.getElementById('standard').value,
                algorithm:document.getElementById('algorithm').value,
                type_name:document.getElementById('type_name').value,
                blank_algorithm:document.getElementById('blank_algorithm').value,
                volume:document.getElementById('volume').value,
                variable:variable,
                other_algorithm:other_algorithm,
                other_variable:other_variable
            };
            console.log(data);
            //发异步，把数据提交给php
            $.ajax({
                url: '/admin/standard/save/{$id}', // 你的 PHP 脚本的 URL  
                type: 'post', // 请求类型，可以是 'GET' 或 'POST'  
                dataType: 'json', // 预期服务器返回的数据类型  
                data: {data:standard},
                success: function(data) { 
                    layer.alert("增加成功", {icon: 6},function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.location.reload();
                        parent.layer.close(index);
                    });
                }
            });
            return false;
          });
        });
    </script>
  </body>
</html>